import { dialog } from '@gis/lib/components/antd-dialog';

function openWarnVideoDialog(data, afterClose) {
  if (typeof afterClose !== 'function') {
    afterClose = () => {};
  }
  dialog({
    content: () => import('./components/warn-video-dialog.vue'),
    contentProps: { data },
    dialogProps: {
      title: '告警',
      width: 'large',
      height: 'fixed',
      footer: null,
      maskClosable: false,
      afterClose: afterClose,
    },
  });
}

function openDeviceWarnDialog(data, afterClose) {
  if (typeof afterClose !== 'function') {
    afterClose = () => {};
  }
  dialog({
    content: () => import('./components/warn-device-dialog.vue'),
    contentProps: { data },
    dialogProps: {
      title: '物联网设备告警',
      footer: null,
      showBorder: false,
      maskClosable: false,
      afterClose: afterClose,
      bodyStyle: { padding: 0 },
    },
  });
}

function openYanGanDialog(data, afterClose) {
  if (typeof afterClose !== 'function') {
    afterClose = () => {};
  }
  dialog({
    content: () => import('./components/warn-yangan-dialog.vue'),
    contentProps: { data },
    dialogProps: {
      // title: data && data.isEvent === true ? '事件详情' : '告警详情',
      title: '详情',
      width: 'large',
      height: 'fixed',
      footer: null,
      afterClose: afterClose,
      bodyStyle: { padding: 0 },
    },
  });
}

function OpenSingletonDialog(dialogOpener, params, afterClose) {
  if (!OpenSingletonDialog.prototype.showing) {
    OpenSingletonDialog.prototype.showing = true;
    dialogOpener(params, () => {
      OpenSingletonDialog.prototype.showing = false;
      typeof afterClose === 'function' && afterClose();
    });
  }
}

export const showWarnDialog = function (data, afterClose) {
  OpenSingletonDialog(openWarnVideoDialog, data, afterClose);
};

export const showDeviceWarnDialog = function (data, afterClose) {
  OpenSingletonDialog(openDeviceWarnDialog, data, afterClose);
};

export const showYanGanWarnDialog = function (data, afterClose) {
  //websocket推消息来关闭弹窗，第二次后面不会自动弹出
  OpenSingletonDialog.prototype.showing = false;
  OpenSingletonDialog(openYanGanDialog, data, afterClose);
};
